#!/bin/bash
if [ $# -gt 0 ]; then
    if [ $1 == "compile" ]; then
        javac -sourcepath ./src ./src/*/*.java 
    else
        if [ $1 == "test" ]; then
            # check what test is wanted
            if [ $# -gt 1 ]; then
                if [ $2 == "case" ]; then
                    java -cp src junit.TestCase
                else
                    if [ $2 == "op" ]; then
                        java -cp src junit.TestOp
                    else
                        if [ $2 == "gates" ]; then
                            java -cp src junit.TestGate
                        else
                            if [ $2 == "io" ]; then
                                java -cp src junit.inAndOut
                            else
                                if [ $2 == "function" ]; then
                                    echo "This test should print the 10 first Fibonacci numbers"
                                    java -cp src junit.Fibo
                                else
                                    if [ $2 == "if" ]; then
                                        java -cp src junit.TestIf
                                    else
                                        if [ $2 == "while" ]; then
                                            java -cp src junit.TestWhile
                                        fi
                                    fi
                                fi
                            fi
                        fi
                    fi
                fi
            else
                echo "Possible options for test:"
                echo "  op : test on arithmetic operations : + - * / and %"
                echo "  gates : test on logical gates : NOT, AND and OR"
                echo "  io : test on input and output"
                echo "  function : test of a function computing Fibonacci numbers"
                echo "  case : test of the case block"
                echo "  if : tests on the if block"
                echo "  while : tests on the while block"
            fi  
        else
            if [ $1 == "clean" ]; then
                rm ./src/*/*.class
            else
                # print help message
                echo "Possible options:"
                echo "  help : show this message"
                echo "  compile : compile all the java files of the project"
                echo "  clean : remove all the class files of the project"
                echo "  test : launch tests (more info when running with option test)"
            fi
        fi  
    fi
else
    echo "Run with option \"help\" to show the possible options"
fi    
